<template>
  <div>
    <div class="head">
      <div>
        <img :src="artist.cover" alt="" />
      </div>
      <div class="info">
        <h2>{{ artist.name }}</h2>
        <div class="transName" v-if="artist.transNames">
          {{ artist.transNames[0] }}
        </div>
        <div class="buttons">
          <span> <i class="el-icon-folder-add"></i> 收藏</span
          ><span> <i class="el-icon-user"></i> 个人主页</span>
        </div>
        <div class="nums">
          <span>单曲数:{{ artist.musicSize }}</span>
          <span>专辑数:{{ artist.albumSize }}</span>
          <span>MV数:{{ artist.mvSize }}</span>
        </div>
      </div>
    </div>
    <div class="main">
      <div class="bar">
        <div>
          <span
            :class="{ active: isActive('/zhuanji') }"
            @click="tolink('zhuanji')"
            >专辑</span
          >
          <span :class="{ active: isActive('/mv') }" @click="tolink('mv')"
            >MV</span
          >
          <span :class="{ active: isActive('/info') }" @click="tolink('info')"
            >歌手详情</span
          >
          <span :class="{ active: isActive('/simi') }" @click="tolink('simi')"
            >相似歌手</span
          >
        </div>
      </div>
      <router-view @toArtist="getArtist" @getmusic="getmusic"></router-view>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      artist: {},
    };
  },
  methods: {
    tolink(path) {
      this.$router.push({ name: path, query: { id: this.$route.query.id } });
    },
    getArtist() {
      this.$request({
        url: "/artist/detail",
        params: {
          id: this.$route.query.id,
        },
      }).then((success) => {
        this.artist = success.data.data.artist;
      });
    },
    getmusic() {
      this.$emit('getId')
    },
  },

  computed: {
    isActive() {
      return function (path) {
        return this.$route.path.includes(path);
      };
    },
  },
  mounted() {
    this.$request({
      url: "/artist/detail",
      params: {
        id: this.$route.query.id,
      },
    }).then((success) => {
      this.artist = success.data.data.artist;
    });
  },
};
</script>

<style scoped>
.head {
  display: flex;
}
.head div:nth-child(1) {
  margin-right: 20px;
  width: 200px;
}
.head div img {
  width: 200px;
  border-radius: 10px;
}
.transName {
  margin: 10px 0;
}
.buttons {
  margin-top: 20px;
}
.info .buttons span {
  display: inline-block;
  padding: 10px 20px;
  border: 1px solid #ccc;
  border-radius: 18px;
  margin-right: 10px;
}
.nums {
  margin-top: 20px;
}
.nums span {
  margin-right: 20px;
}
.bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 40px 0;
}
.bar span {
  display: inline-block;
  height: 30px;
  line-height: 30px;
  margin-right: 20px;
  cursor: pointer;
}
.active {
  border-bottom: 4px solid #ec4141;
}
</style>